/**
 * @description to html
 * @author wangfupeng
 */

import { SlateElement } from '@wangeditor/editor';
import { DavinciMedia } from './custom-types';

function videoToHtml(elem: SlateElement, childrenHtml?: string): string {
	const { src = '', poster = '', width = 'auto', height = 'auto', suffix = '', fileName = '', style = {} } = elem as DavinciMedia;
	const isAudio = ['mp3', 'flac', 'wav', 'ogg', 'aac'].includes(suffix.toLowerCase());
	const { verticalAlign = '' } = style;
	let styleStr = '';
	if (verticalAlign) styleStr += `vertical-align:${verticalAlign}`;
	if (isAudio) {
		return `<audio data-w-e-type="davinci-media" data-w-e-is-void controls="true" width="${width}" height="${height}" src="${src}"style="${styleStr}"></audio>`;
	} else {
		return `<video data-w-e-type="davinci-media" data-w-e-is-void poster="${poster}" controls="true" width="${width}" height="${height}" src="${src}"style="${styleStr}"></video>`;
	}
}

export const videoToHtmlConf = {
	type: 'davinci-media',
	elemToHtml: videoToHtml
};
